<?php

  /*
   * Validaiton for Document content
   */

  function documents_form_validation($form) {

	/*District Validation*/
   distvalidation($form['field_state']['und']['#value']);
   //print_r($dist_value);

    // Bad character validations
    chkbadchar($form['title']['#value'], $form['title']['#title'], 'title');
	chkbadchar($form['field_dockeywords']['und'][0]['value']['#value'], $form['field_dockeywords']['und'][0]['value'] ['#title'], 'field_act_keyword');
	chkbadchar($form['field_docothers']['und'][0]['value']['#value'],$form['field_docothers']['und'][0]['value']['#title'], 'field_docothers');

	// minimum length charcter
  	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
	minilength_validation($form['field_dockeywords']['und'][0]['value']['#value'], 5, $form['field_dockeywords']['und'][0]['value']['#title'],'field_dockeywords');
  	//minilength_validation($form['field_dockeywords'][0]['value']['#value'], 5, $form['field_dockeywords']['#title'],'field_dockeywords');

	// bad URL Check
	badurl($form['field_docurl']['und'][0]['value']['#value'],$form['field_docurl']['und'][0]['value']['#title'],'field_docurl');

    // Form type validation
    $form_type = $form['field_doctype'];
	//echo $form_type['value']['#value']; die;
    if ($form['field_doctype']['und']['#value'] == 'online') {
	  url_validation($form['field_docurl']['und'][0]['value']['#value']);
    }

  if ($form['field_doctype']['und']['#value'] == 'download') {
	$filename = $form['field_docupload']['und'][0]['#file'];
	$filename->filename;
    file_upload_validation_D7($filename->filename,$form['field_doctype']['und']['#title']);

  }

  //echo "sel".$form['field_doc_year']['und'][0]['value']['#value'];

   //Year
	check_integer_with_hypan($form['field_doc_year']['und'][0]['value']['#value'],$form['field_doc_year']['und'][0]['#title'],'field_doc_year');
	docu_year($form['field_doc_year']['und'][0]['value']['#value'],$form['field_doc_year']['und'][0]['#title'],'field_doc_year');
	//docu_year($form['field_doc_year'][0]['value']['#value'],$form['field_doc_year']['#title'],'field_doc_year');

 } // function documents_form_validation()

  function documents_presave_validation($node) {
    $reference_url = $node->field_docurl[0]['value'];
    $node->field_docurl[0]['value'] = url_validation($reference_url);
  } // function form_presave_validation()
